/**
 * 
 */
package com.yidu.drug.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yidu.drug.common.Page;
import com.yidu.drug.common.Tools;
import com.yidu.drug.dao.DrugProductionModelMapper;
import com.yidu.drug.dao.ProductionEnterpriseModelMapper;
import com.yidu.drug.dao.ProductionModelMapper;
import com.yidu.drug.model.ProductionEnterpriseModel;
import com.yidu.drug.model.ProductionModel;
import com.yidu.drug.service.ProductionService;

/**
 * 生产计划的service实现类
 * @author 王志伟
 * @date 2018年8月27日 下午7:08:06
 * @version 1.0
 */
@Service
public class ProductionServiceImpl implements ProductionService{
	//生产计划的DAO
	@Resource
	private ProductionModelMapper proDao;
	
	//生产地址DAO
	@Resource
	private ProductionEnterpriseModelMapper preDao;
	
	//药品生产DAO
	@Resource
	private DrugProductionModelMapper dpDao;
	
	@Override
	public int deleteByPrimaryKey(String proId,String preId) {
		preDao.deleteByPrimaryKey(preId);
		dpDao.deleteByProId(proId);
		return proDao.deleteByPrimaryKey(proId);
	}

	@Override
	public int insert(ProductionModel record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int insertSelective(ProductionModel record) {
		record.setProId(Tools.getRandomUUID());
		record.setIsva(Tools.ISVA_YES);
		return proDao.insertSelective(record);
	}

	@Override
	public ProductionModel selectByPrimaryKey(String proId) {
		// TODO Auto-generated method stub
		return proDao.selectByPrimaryKey(proId);
	}

	@Override
	public int updateByPrimaryKeySelective(ProductionModel record) {
		// TODO Auto-generated method stub
		return proDao.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateByPrimaryKey(ProductionModel record) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Map<String, Object> findAll(String limit, String page, String entName) {
		//NEW一个生产的模型,加入页面信息和企业名称
		ProductionModel proModel = new ProductionModel();
		Page pa=new Page();
		pa.setPage(Integer.valueOf(page));
		pa.setRows(Integer.valueOf(limit));
		proModel.setPage(pa);
		proModel.setEntName(entName);
		//查询所有信息或者按条件查询
		List<ProductionModel> list=proDao.findAll(proModel);
		for (ProductionModel productionModel : list) {
			String preId=productionModel.getPreId();
			if(!Tools.isEmpty(preId)){
	        	ProductionEnterpriseModel pre=preDao.selectByPrimaryKey(preId);
	  	        System.out.println("地址名称"+pre.getPreSite());
	  	        productionModel.setArea(pre.getPreSite());
	        }
		}
		//查询出的信息的总行数
		Long count = proDao.findRows(proModel);
		System.out.println("总行数"+count);
		//加入MAP集合
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("code",0);
		map.put("msg","");
		map.put("count",count);
		map.put("data", list);
		return map;
	}

}
